package com.laiketui.app.controller.bargain;

import com.laiketui.app.api.bargain.BargainService;
import com.laiketui.core.annotation.ParamsMapping;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.root.annotation.HttpApiMethod;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 砍价
 *
 * @author Trick
 * @date 2021/4/16 15:15
 */
@Api(tags = "插件-满减")
@RestController
@RequestMapping("/bargain")
public class BargainController {

    @Autowired
    private BargainService bargainService;


    @ApiOperation("砍价商品列表")
    @PostMapping("/bargainhome")
    @HttpApiMethod(urlMapping = "app.bargain.bargainhome")
    public Result index(MainVo vo) {
        try {
            return Result.success(bargainService.getBargainGoodsList(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("我的砍价")
    @PostMapping("/mybargain")
    @HttpApiMethod(urlMapping = "app.bargain.mybargain")
    public Result mybargain(MainVo vo) {
        try {
            return Result.success(bargainService.mybargain(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("立即砍价")
    @PostMapping("/createbargain")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bargainId", value = "砍价活动id", required = true, dataType = "int", paramType = "form")
    })
    @HttpApiMethod(urlMapping = "app.bargain.createbargain")
    public Result createbargain(MainVo vo, @ParamsMapping("bargain_id") int bargainId) {
        try {
            return Result.success(bargainService.createbargain(vo, bargainId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("获取砍价规则")
    @PostMapping("/getRule")
    @HttpApiMethod(urlMapping = "app.bargain.getRule")
    public Result getRule(MainVo vo) {
        try {
            return Result.success(bargainService.getRule(vo));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("获取当前砍价商品详情")
    @PostMapping("/getgoodsdetail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderno", value = "订单号", required = true, dataType = "int", paramType = "form")
    })
    @HttpApiMethod(urlMapping = "app.bargain.getgoodsdetail")
    public Result getgoodsdetail(MainVo vo, @ParamsMapping("order_no") String orderno) {
        try {
            return Result.success(bargainService.getgoodsdetail(vo, orderno));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("好友帮砍")
    @PostMapping("/helpbargain")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderno", value = "订单号", required = true, dataType = "int", paramType = "form")
    })
    @HttpApiMethod(urlMapping = "app.bargain.helpbargain")
    public Result helpbargain(MainVo vo, @ParamsMapping("order_no") String orderno) {
        try {
            return Result.success(bargainService.helpbargain(vo, orderno));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

}
